package com.zrrd.gmall.product.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrrd.gmall.common.result.Result;
import com.zrrd.gmall.model.product.BaseSaleAttr;
import com.zrrd.gmall.model.product.BaseTrademark;
import com.zrrd.gmall.product.service.BaseTrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {
    @Autowired
    private BaseTrademarkService baseTrademarkService;
    @GetMapping("/{page}/{limit}")
    public Result<Page<BaseTrademark>> baseTrademark(@PathVariable("page") Integer page,
                                                     @PathVariable("limit") Integer limit){
        Page<BaseTrademark> pageInfo =new Page<>(page,limit);
        baseTrademarkService.page(pageInfo,null);
        return Result.ok(pageInfo);

    }
    //添加品牌
    @PostMapping("/save")
    public Result<String>  save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok("成功");
    }
    @GetMapping("/get/{id}")
    public Result<BaseTrademark> get(@PathVariable("id")Long id){
        BaseTrademark byId = baseTrademarkService.getById(id);
        return Result.ok(byId);
    }
    @PutMapping("/update")
    public Result<String> update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok("成功");
    }
    @DeleteMapping("/remove/{id}")
    public Result<String> remove(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return Result.ok("成功");
    }
    //添加spu时使用查询全部不分页
    @GetMapping("/getTrademarkList")
    public Result<List<BaseTrademark>> getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list(null);
        return Result.ok(list);
    }



}
